package com.ruoyi.studylog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.studylog.domain.UserStudyLog;
import com.ruoyi.studylog.service.IUserStudyLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学习记录表Controller
 * 
 * @author ruoyi
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/studylog/studylog")
public class UserStudyLogController extends BaseController
{
    @Autowired
    private IUserStudyLogService userStudyLogService;

    /**
     * 查询学习记录表列表
     */
    @PreAuthorize("@ss.hasPermi('studylog:studylog:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserStudyLog userStudyLog)
    {
        startPage();
        List<UserStudyLog> list = userStudyLogService.selectUserStudyLogList(userStudyLog);
        return getDataTable(list);
    }

    /**
     * 导出学习记录表列表
     */
    @PreAuthorize("@ss.hasPermi('studylog:studylog:export')")
    @Log(title = "学习记录表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserStudyLog userStudyLog)
    {
        List<UserStudyLog> list = userStudyLogService.selectUserStudyLogList(userStudyLog);
        ExcelUtil<UserStudyLog> util = new ExcelUtil<UserStudyLog>(UserStudyLog.class);
        return util.exportExcel(list, "学习记录表数据");
    }

    /**
     * 获取学习记录表详细信息
     */
    @PreAuthorize("@ss.hasPermi('studylog:studylog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userStudyLogService.selectUserStudyLogById(id));
    }

    /**
     * 新增学习记录表
     */
    @PreAuthorize("@ss.hasPermi('studylog:studylog:add')")
    @Log(title = "学习记录表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserStudyLog userStudyLog)
    {
        return toAjax(userStudyLogService.insertUserStudyLog(userStudyLog));
    }

    /**
     * 修改学习记录表
     */
    @PreAuthorize("@ss.hasPermi('studylog:studylog:edit')")
    @Log(title = "学习记录表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserStudyLog userStudyLog)
    {
        return toAjax(userStudyLogService.updateUserStudyLog(userStudyLog));
    }

    /**
     * 删除学习记录表
     */
    @PreAuthorize("@ss.hasPermi('studylog:studylog:remove')")
    @Log(title = "学习记录表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userStudyLogService.deleteUserStudyLogByIds(ids));
    }
}
